-module(lib_misc).
-export([print/1]).
-export([for/3]).
-export([sum/1]).
% -export([process_todo/1]).
-export([odds_and_evens/1]).
-export([oc/1]).
-export([oc/3]).

% print
print(X) -> X.

% for loop
for(Max,Max, F) -> [F(Max)];
for(I, Max, F) -> [F(I)|for(I+1, Max, F)].

% to use: lib_misc:for(1, 10, fun(X) -> X end).

% sum : lib_misc:sum([1,2,3])
sum([H|T]) -> H + sum(T);
sum([]) -> 0.

% using a record in a function
% process_todo(#todo{status=S, who=W, text=T} = R) -> S.

%
odds_and_evens(L) ->
	Odds = [X || X <- L, (X rem 2) =:= 1],
	Evens = [X || X <- L, (X rem 2) =:= 0],
	{Odds, Evens}.
		
oc(L) ->
	oc(L, [], []).
		
oc([H|T], Odds, Evens) ->
	case (H rem 2) of
		1 -> oc(T, [H|Odds], Evens);
		0 -> oc(T, Odds, [H|Evens])
	end;
	
oc([], Odds, Evens) ->
	{Odds, Evens}.